//
//  GoogleOpenViewModel.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/6/6.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class GoogleOpenViewModel: BaseViewModel {
   open var model:SecurityModel? //传递的model
    var googlePassWord:String = ""
    lazy var closeRequest:CloseGoogleRequest = {
        let api = CloseGoogleRequest()
        api.dataReformer = self
        api.paramSource = self
        api.delegate = self
        return api
    }()
    lazy var openRequest:OpenGoogleRequest = {
        let api = OpenGoogleRequest()
        api.dataReformer = self
        api.paramSource = self
        api.delegate = self
        return api
    }()
    
    func closeGoogle(passWord:String, success:@escaping success ,fail: @escaping fail) {
        googlePassWord = passWord
        if (model?.isOpenGoogle)! {
            self.request(request: closeRequest, success: success, fail: fail)
        }else {
            self.request(request: openRequest, success: success, fail: fail)
        }
    }
}
extension GoogleOpenViewModel:RequestCallBack,RequestDataReformer,RequestParamSource {
    func reform(_ request: BaseRequest, _ data: [String : Any]?) {
        if successBlock != nil {
            successBlock!(data)
        }
    }
    
    func requestDidSucess(_ request: BaseRequest) {
        
    }
    
    func requestDidFail(_ request: BaseRequest) {
        if failBlock != nil {
            failBlock!(request)
        }
    }
    
    func requestParams(_ request: BaseRequest) -> [String : Any]? {
        var pramas: [String:Any] = [:]
        if let _ = request as? CloseGoogleRequest {
            pramas.updateValue(googlePassWord, forKey: "googleCode")
            pramas.updateValue(2, forKey: "type")
        }else if let _ = request as? OpenGoogleRequest {
//            pramas.updateValue(googlePassWord, forKey: "googleCode")
            pramas.updateValue(2, forKey: "type")
        }
        
        return pramas
    }
    
    
}
